package gek.uni.diplom.ocl.example.utils;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EParameter;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.ocl.OCL;
import org.eclipse.ocl.ParserException;
import org.eclipse.ocl.Query;
import org.eclipse.ocl.ecore.CallOperationAction;
import org.eclipse.ocl.ecore.Constraint;
import org.eclipse.ocl.ecore.EcoreEnvironmentFactory;
import org.eclipse.ocl.ecore.SendSignalAction;
import org.eclipse.ocl.helper.OCLHelper;

public class Utils {

  public static Query<EClassifier, EClass, EObject> evaluateConditionForClass(EClassifier clazz,
      String expression) throws ParserException {
    OCL<EPackage, EClassifier, EOperation, EStructuralFeature, EEnumLiteral, EParameter, EObject, CallOperationAction, SendSignalAction, Constraint, EClass, EObject> ocl;
    ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);

    OCLHelper<EClassifier, EOperation, ?, Constraint> helper =
        ocl.createOCLHelper();

    helper.setContext(clazz);
    Constraint constraint =
      helper.createInvariant(expression);
      
    Query<EClassifier, EClass, EObject> queryEval =
        ocl.createQuery(constraint);
    return queryEval;
  }
}
